/*
 * global.c
 *
 *  Created on: 2016-10-3
 *      Author: m
 */
#include "global.h"
#include "clock.h"
#include "i8259.h"
#include "tty.h"
#include "console.h"
#include "task_sys.h"
#include "hd.h"
#include "fs.h"

u16 g_cur_pos = 0x0; //@bss
u16 g_tty_start_addr = 0x0000;
char g_text_attr = 0xF;

GDT_PTR g_gdt_ptr;
GDT_PTR g_idt_ptr;
DESCRIPTOR g_gdt[GDT_ITEM_COUNT];
GATE g_idt[IDT_ITEM_COUNT];

PROCESS g_proc_table[NR_TASKS];
PROCESS* g_proc_ready;
TSS g_tss;

int g_reenter = 0;
#define PRIO_BASE   (10)
TASK g_task_table[NR_TASKS] = {
    {tty_task, 0, STACK_SIZE, PRIO_BASE * 10,  "kb loop "},
    {task_sys, 0, STACK_SIZE, PRIO_BASE * 10,  "sys task"},
    {task_hd, 0, STACK_SIZE,  PRIO_BASE * 10,  "hd task "},
    {task_fs, 0, STACK_SIZE,  PRIO_BASE * 9,   "fs task "},
    {test_a, 0,  STACK_SIZE, PRIO_BASE * 6,    "PrcA    "},
    {test_b, 0,  STACK_SIZE, PRIO_BASE * 5,    "PrcB    "},
    {test_c, 0,  STACK_SIZE, PRIO_BASE * 3,    "PrcC    "},
};

irq_handler g_irq_table[] = {
    clock_handler, //hwint0
    hw_int_proc, //hwint1
    hw_int_proc, //hwint2
    hw_int_proc, //hwint3
    hw_int_proc, //hwint4
    hw_int_proc, //hwint5
    hw_int_proc, //hwint6
    hw_int_proc, //hwint7
    hw_int_proc, //hwint8
    hw_int_proc, //hwint9
    hw_int_proc, //hwint10
    hw_int_proc, //hwint11
    hw_int_proc, //hwint12
    hw_int_proc, //hwint13
    hw_int_proc, //hwint14
    hw_int_proc, //hwint15
};

system_call g_syscall_tab[NR_SYSCALL] = {
    (system_call)post_impl,
    (system_call)write_impl,
};

unsigned int g_ticks = 0;

TTY g_tty_tab[TTY_COUNT] = {0};
CONSOLE g_console_tab[TTY_COUNT] = {0};
u8 g_cur_tty_idx = 0;
DRV_INFO g_drv_map[] = { //下标为主设备号，通过主设备号，找到对应驱动task的pid等信息
        {TASK_NONE}, //0: preserved
        {TASK_NONE}, //1: floppy driver, reserved
        {TASK_NONE}, //2: cdrom driver, reserved
        {TASK_IDX_HD_DRV}, //3: hd driver
        {TASK_IDX_TTY}, //4: hd driver
        {TASK_NONE}, //5: scsi disk driver, reserved
};


FILE_DESC g_fd_table[FILE_DESC_MAX] = {0};
